package com.xybean.action;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.xybean.action.base.AbstractAction;
import com.xybean.bean.Product;
import com.xybean.dao.DAO;

@Controller("Product_Action")
@Scope("prototype")
@SuppressWarnings("serial")
public class ProductAction extends AbstractAction {

	@Autowired
	private DAO<Product> productDao;
	
	private Product product;

	private List<Product> productList = new ArrayList<Product>();

	public String execute()throws Exception{

		String[] ordertype = {"desc","desc"};
		String[] property = {"productRate","sale"};
		productList = productDao.getList(0, 
				ordertype, 
				property, 
				Restrictions.eq("activity", new Integer(1))
		);
		return SUCCESS;
	}

	public String simpleProduct()throws Exception{

		product = productDao.get(id);
		return "simpleproduct";
	}

	public DAO<Product> getProductDao() {
		return productDao;
	}

	public void setProductDao(DAO<Product> productDao) {
		this.productDao = productDao;
	}

	public List<Product> getProductList() {
		return productList;
	}

	public void setProductList(List<Product> productList) {
		this.productList = productList;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}



}
